
/**
 * AppleIIGo
 * List class
 * (C) 2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 */

#include "List.h"

List::List() {
	head = 0;
	setStart();
}

List::~List() {
	setStart();
	while(isNext())
		remove();
}

bool List::insert(void * data) {
	ListType * element = new ListType;
	if (!element)
		return false;
	
	element->data = data;
	element->next = *pointer;
	*pointer = element;
	
	next();
	
	return true;
}

void * List::get() {
	if (*pointer)
		return (*pointer)->data;
	else
		return 0;
}

void * List::remove() {
	ListType * element = *pointer;
	*pointer = element->next;
	void * data = element->data;
	delete element;
	return data;
}

void List::setStart() {
	pointer = &head;
}

bool List::isNext() {
	return *pointer;
}

void List::next() {
	pointer = &((*pointer)->next);
}
